package empox.pos.system.pos;

import java.util.ArrayList;
import java.util.List;

import empox.common.EmpoxFunc;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SetInfoAdapter extends BaseAdapter {
	Context con;

	static List<SetInfoBeen> showlist = new ArrayList<SetInfoBeen>();

	public SetInfoAdapter(Context con) {
		this.con = con;
	}

	public void setValue(String type) {
		if (type.compareTo("1") == 0) {
			showlist = DBSet.pos_list;
		} else {
			showlist = DBSet.parameter_list;
		}
	}

	public int getCount() {
		return showlist.size();
	}

	public Object getItem(int position) {
		return showlist.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	static class SH {
		TextView tv1;
		TextView tv2;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		SH sh = new SH();

		if (convertView == null) {
			convertView = new LinearLayout(con);
			((LinearLayout) convertView).setGravity(Gravity.CENTER);

			sh.tv1 = new TextView(con);
			sh.tv1.setWidth(250);
			sh.tv1.setHeight(50);
			sh.tv1.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv1);

			sh.tv2 = new TextView(con);
			sh.tv2.setWidth(250);
			sh.tv2.setHeight(50);
			sh.tv2.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv2);

			convertView.setTag(sh);
		} else {
			sh = (SH) convertView.getTag();
		}

		SetInfoBeen sib = showlist.get(position);

		sh.tv1.setText(sib.showName);

		if (sib.name.compareTo("mobileno") == 0) {
			sib.value = EmpoxFunc.getSimNumber(con);
		}
		sh.tv2.setText(sib.value);

		return convertView;
	}

}
